#include <iostream>
#include <sstream>
#include <string>
#include <regex>
using namespace std;


// regular expression
struct match_wrapper
{
	match_wrapper() : success{false} {}
	match_wrapper(smatch&& m) : success{true}, m{std::move(m)} {}

	operator bool() { return success; }
	string operator[](int i) { return std::move(m[i].str()); }

private:
	bool success;
	smatch m;
};

static match_wrapper match(const regex& re, const string& s)
{
	smatch m;
	if (regex_match(s, m, re))
		return {std::move(m)};
	return {};
}


// conversion
static int name2addr(const string& name)
{
	int addr = 0;
	for (auto c: name)
		addr = addr * 26 + c - 'A' + 1;
	return addr;
}

static string addr2name(int addr)
{
	stringstream name;
	while (addr--) {
		name << char(addr%26 + 'A');
		addr /= 26;
	}

	auto s = name.str();
	return string{s.rbegin(), s.rend()};
}


// rc = row-column
// ad = alpha-digit
static regex re_rc{"R(\\d+)C(\\d+)"};
static regex re_ad{"([A-Z]+)(\\d+)"};
struct bad_format {};


int main()
{
	string line;
	getline(cin, line);	// skip first line

	while (getline(cin, line)) {
		if (auto m = match(re_rc, line))
			cout << addr2name(atoi(m[2].c_str())) << m[1] << endl;
		else if (auto m = match(re_ad, line))
			cout << 'R' << m[2] << 'C' << name2addr(m[1]) << endl;
		else throw bad_format{};
	}
}
